public class QauickSort {
    public static void main(String[] args) {
        int[] arr = {4,15,36,22,5,9,2,1,6,7,8};
        quick(arr,0,arr.length-1);
        for (int i = 0; i < arr.length; i++) {
            System.out.print(arr[i]+" ");
        }
    }
    public static void quick(int[] arr,int start,int end) {
        int left = start;
        int right = end;
        int tmp = arr[left];
        while (left < right) {
            while (arr[left] < tmp && left < right) {
                left++;
            }
            while (arr[right] > tmp && left < right) {
                right--;
            }
            if(arr[left] == arr[right] && left < right) {
                left++;
            }else {
                int tmpe = arr[right];
                arr[right] = arr[left];
                arr[left] = tmpe;
            }
        }
        if (left-1 > start) {
            quick(arr,start,left-1);
        }
        if(right+1 < end) {
            quick(arr,right+1,end);
        }

    }
}
